<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="告警标识,告警的记录标识" prop="warningId">
        <el-input
          v-model="queryParams.warningId"
          placeholder="请输入告警标识,告警的记录标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库房标识" prop="whId">
        <el-input
          v-model="queryParams.whId"
          placeholder="请输入库房标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周转柜编号" prop="cabinetBarCode">
        <el-input
          v-model="queryParams.cabinetBarCode"
          placeholder="请输入周转柜编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="柜单元编号" prop="cabinetUnitNo">
        <el-input
          v-model="queryParams.cabinetUnitNo"
          placeholder="请输入柜单元编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部件编号,零部件编号" prop="partNo">
        <el-input
          v-model="queryParams.partNo"
          placeholder="请输入部件编号,零部件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="管理单位编号" prop="orgNo">
        <el-input
          v-model="queryParams.orgNo"
          placeholder="请输入管理单位编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警描述,
告警内容描述如:
0101:柜门损坏
0102:储位损坏
0103:摄像头损坏
0201:单相表库存超期告警
0202:三相表库存超期告警
0203:领出未装超期告警" prop="warningDescription">
        <el-input
          v-model="queryParams.warningDescription"
          placeholder="请输入告警描述,
告警内容描述如:
0101:柜门损坏
0102:储位损坏
0103:摄像头损坏
0201:单相表库存超期告警
0202:三相表库存超期告警
0203:领出未装超期告警"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警工单号,发生业务告警时关联的业务工单号" prop="warningAppNo">
        <el-input
          v-model="queryParams.warningAppNo"
          placeholder="请输入告警工单号,发生业务告警时关联的业务工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警时间" prop="waringDate">
        <el-date-picker clearable
          v-model="queryParams.waringDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择告警时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作标识" prop="operId">
        <el-input
          v-model="queryParams.operId"
          placeholder="请输入操作标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['storage:mdWarningInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['storage:mdWarningInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['storage:mdWarningInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['storage:mdWarningInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mdWarningInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="告警标识,告警的记录标识" align="center" prop="warningId" />
      <el-table-column label="库房标识" align="center" prop="whId" />
      <el-table-column label="周转柜编号" align="center" prop="cabinetBarCode" />
      <el-table-column label="柜单元编号" align="center" prop="cabinetUnitNo" />
      <el-table-column label="部件编号,零部件编号" align="center" prop="partNo" />
      <el-table-column label="管理单位编号" align="center" prop="orgNo" />
      <el-table-column label="告警类型,01:设备告警
02:业务告警
03:温湿度告警" align="center" prop="warningType" />
      <el-table-column label="告警描述,
告警内容描述如:
0101:柜门损坏
0102:储位损坏
0103:摄像头损坏
0201:单相表库存超期告警
0202:三相表库存超期告警
0203:领出未装超期告警" align="center" prop="warningDescription" />
      <el-table-column label="告警工单号,发生业务告警时关联的业务工单号" align="center" prop="warningAppNo" />
      <el-table-column label="告警时间" align="center" prop="waringDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.waringDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作标识" align="center" prop="operId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['storage:mdWarningInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['storage:mdWarningInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改告警信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="告警标识,告警的记录标识" prop="warningId">
          <el-input v-model="form.warningId" placeholder="请输入告警标识,告警的记录标识" />
        </el-form-item>
        <el-form-item label="库房标识" prop="whId">
          <el-input v-model="form.whId" placeholder="请输入库房标识" />
        </el-form-item>
        <el-form-item label="周转柜编号" prop="cabinetBarCode">
          <el-input v-model="form.cabinetBarCode" placeholder="请输入周转柜编号" />
        </el-form-item>
        <el-form-item label="柜单元编号" prop="cabinetUnitNo">
          <el-input v-model="form.cabinetUnitNo" placeholder="请输入柜单元编号" />
        </el-form-item>
        <el-form-item label="部件编号,零部件编号" prop="partNo">
          <el-input v-model="form.partNo" placeholder="请输入部件编号,零部件编号" />
        </el-form-item>
        <el-form-item label="管理单位编号" prop="orgNo">
          <el-input v-model="form.orgNo" placeholder="请输入管理单位编号" />
        </el-form-item>
        <el-form-item label="告警描述,
告警内容描述如:
0101:柜门损坏
0102:储位损坏
0103:摄像头损坏
0201:单相表库存超期告警
0202:三相表库存超期告警
0203:领出未装超期告警" prop="warningDescription">
          <el-input v-model="form.warningDescription" placeholder="请输入告警描述,
告警内容描述如:
0101:柜门损坏
0102:储位损坏
0103:摄像头损坏
0201:单相表库存超期告警
0202:三相表库存超期告警
0203:领出未装超期告警" />
        </el-form-item>
        <el-form-item label="告警工单号,发生业务告警时关联的业务工单号" prop="warningAppNo">
          <el-input v-model="form.warningAppNo" placeholder="请输入告警工单号,发生业务告警时关联的业务工单号" />
        </el-form-item>
        <el-form-item label="告警时间" prop="waringDate">
          <el-date-picker clearable
            v-model="form.waringDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择告警时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="操作标识" prop="operId">
          <el-input v-model="form.operId" placeholder="请输入操作标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdWarningInfo, getMdWarningInfo, delMdWarningInfo, addMdWarningInfo, updateMdWarningInfo } from "@/api/storage/mdWarningInfo";

export default {
  name: "MdWarningInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警信息表格数据
      mdWarningInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        warningId: null,
        whId: null,
        cabinetBarCode: null,
        cabinetUnitNo: null,
        partNo: null,
        orgNo: null,
        warningType: null,
        warningDescription: null,
        warningAppNo: null,
        waringDate: null,
        operId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        warningId: [
          { required: true, message: "告警标识,告警的记录标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询告警信息列表 */
    getList() {
      this.loading = true;
      listMdWarningInfo(this.queryParams).then(response => {
        this.mdWarningInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        warningId: null,
        whId: null,
        cabinetBarCode: null,
        cabinetUnitNo: null,
        partNo: null,
        orgNo: null,
        warningType: null,
        warningDescription: null,
        warningAppNo: null,
        waringDate: null,
        operId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.warningId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加告警信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const warningId = row.warningId || this.ids
      getMdWarningInfo(warningId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改告警信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.warningId != null) {
            updateMdWarningInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMdWarningInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const warningIds = row.warningId || this.ids;
      this.$modal.confirm('是否确认删除告警信息编号为"' + warningIds + '"的数据项？').then(function() {
        return delMdWarningInfo(warningIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('storage/mdWarningInfo/export', {
        ...this.queryParams
      }, `mdWarningInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
